package com.zch.starter.sentinel.springboot.starter.config;

import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.List;

public class SentinelNacosConfig {
    @Autowired
    ReadableDataSource<String, List<FlowRule>> flowRuleDataSource;
    @Autowired
     ReadableDataSource<String, List<ParamFlowRule>> paramFlowRuleDataSource;

    // 2. 注册规则管理器（依赖数据源Bean）
    @PostConstruct
    public void init() {
        FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
        ParamFlowRuleManager.register2Property(paramFlowRuleDataSource.getProperty());
    }

}
